package com.crm.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.crm.entity.Task;
import com.crm.mapper.RuleMapper;
import com.crm.service.RuleService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;

@Service
@RequiredArgsConstructor
public class RuleServiceImpl extends ServiceImpl<RuleMapper, Task> implements RuleService {

    private final RuleMapper ruleMapper;
    private final RedisTemplate redisTemplate ;

    //private static final String CLUE_LIMIT_TIME = ""

    @Override
    public void timeTask(Task task) {
        //ruleMapper.insert(task);

        Map<String, Object> map = new HashMap<>();
        //BeanUtils.copyProperties(task,map); // 注意参数顺序

        map.put("limitTime",task.getLimitTime());
        map.put("limitTimeType",task.getLimitTimeType());
        map.put("repeatGetTime",task.getRepeatGetTime());
        map.put("repeatType",task.getRepeatType());


        String redisKey = "task";

        // 使用 opsForHash 将 Map 存入 Redis
        map.forEach((key, value) -> {
            redisTemplate.opsForHash().put(redisKey,key,value);
        });


    }
}
